package com.runchinaup.smartbelt.launch;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.runchinaup.smartbelt.R;
import com.runchinaup.smartbelt.activity.IndexActivity;

public class LaunchUI extends Activity {

    protected BluetoothAdapter bluetoothAdapter;
    static final int REQUEST_BT = 222;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ui_launch);
        bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        blueisOpen();
    }

    private void blueisOpen() {
        if (!bluetoothAdapter.isEnabled()) {
            Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(intent, REQUEST_BT);
        } else {
            startActivity(new Intent(LaunchUI.this, IndexActivity.class));
            finish();
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        startActivity(new Intent(LaunchUI.this, IndexActivity.class));
        finish();

    }
}
